/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.service.impl;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseMainDetailAuxiliaryInfoRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainDetailAuxiliaryInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainDetailAuxiliaryInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainDetailAuxiliaryInfoService;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 描述: 案件详情补充表 case_main_detail_auxiliary_info 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年05月11日
 */
@Service
@Slf4j
public class CaseMainDetailAuxiliaryInfoServiceImpl extends MyBatisServiceSupport implements ICaseMainDetailAuxiliaryInfoService {

    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;

    /**
     * 描述：更新指定参数信息
     *
     * @param updateInfo {@link CaseMainDetailAuxiliaryInfo}
     * @return Integer 更新成功记录数
     * @author xiangyuyu
     * @date 2022-05-26 13:44
     */
    @Override
    public Integer updateSpecialParam(CaseMainDetailAuxiliaryInfo updateInfo) {
        String id = updateInfo.getId();
        String partyId = updateInfo.getPartyId();
        String caseId = updateInfo.getCaseId();
        if (ObjectUtils.isEmpty(id)) {
            if (ObjectUtils.isEmpty(partyId)) {
                throw new BusinessException("请指定关键字段(id或PartyId)");
            }
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("请指定关键字段(caseId)");
            }
        }
        int uc = 0;
        if (!ObjectUtils.isEmpty(id)) {
            uc = caseMainDetailAuxiliaryInfoMapper.updateByPrimaryKeySelective(updateInfo);
        } else {
            Example update = new Example(CaseMainDetailAuxiliaryInfo.class);
            update.createCriteria().andEqualTo("caseId", caseId)
                    .andEqualTo("partyId", partyId);
            uc = caseMainDetailAuxiliaryInfoMapper.updateByExampleSelective(updateInfo, update);
        }
        return uc;
    }

    /**
     * 描述：获取案件详情补充表记录信息
     *
     * @param request {@link CaseMainDetailAuxiliaryInfo}
     * @return {@link List <CaseMainDetailAuxiliaryInfo>}
     * @author xiangyuyu
     * @date 2022-05-28 22:21
     */
    @Override
    public List<CaseMainDetailAuxiliaryInfo> getCaseMainDetailAuxiliaryInfo(CaseMainDetailAuxiliaryInfoRequest request) {
        String caseId = request.getCaseId();
        Example query = new Example(CaseMainDetailAuxiliaryInfo.class);
        Example.Criteria criteria = query.createCriteria();
        criteria.andEqualTo("caseId", caseId);
        String partyId = request.getPartyId();
        if (!ObjectUtils.isEmpty(partyId)) {
            criteria.andEqualTo("partyId", partyId);
        }
        List<CaseMainDetailAuxiliaryInfo> list = caseMainDetailAuxiliaryInfoMapper.selectByExample(query);
        return list;
    }
    /**
     * 单当事人单案由 更新补充表数据
     * @author liyafeng
     * @date 2022/11/25
      * @param caseMainDetailAuxiliaryInfo
     * @return
     */
    @Override
    public void editSpecialParamSingle(CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo) {
        String id = caseMainDetailAuxiliaryInfo.getId();
        String caseId = caseMainDetailAuxiliaryInfo.getCaseId();
        if (ObjectUtils.isEmpty(id)) {
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("请指定关键字段(caseId)");
            }
        }
        if (!ObjectUtils.isEmpty(id)) {
            caseMainDetailAuxiliaryInfoMapper.updateByPrimaryKeySelective(caseMainDetailAuxiliaryInfo);
        } else {
            Example update = new Example(CaseMainDetailAuxiliaryInfo.class);
            update.createCriteria().andEqualTo("caseId", caseId);
            caseMainDetailAuxiliaryInfoMapper.updateByExampleSelective(caseMainDetailAuxiliaryInfo, update);
        }

    }

    @Override
    public void updateCaseMainDetailAuxiliaryInfo(CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo) {
        String id = caseMainDetailAuxiliaryInfo.getId();
        String caseId = caseMainDetailAuxiliaryInfo.getCaseId();
        if (ObjectUtils.isEmpty(id)) {
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("请指定关键字段(caseId)");
            }
        }
        if (!ObjectUtils.isEmpty(id)) {
            caseMainDetailAuxiliaryInfoMapper.updateByPrimaryKeySelective(caseMainDetailAuxiliaryInfo);
        } else {
            caseMainDetailAuxiliaryInfo.setId(BaseUtil.createUid());
            caseMainDetailAuxiliaryInfoMapper.insertSelective(caseMainDetailAuxiliaryInfo);
        }
    }
}
